#include "base.h"

char *GetTimeStr(char *pStr)
{
	if(!pStr)
		return NULL;
		
	time_t t = time(NULL);
	struct tm *local = localtime(&t);
	
	//YYYY-MM-DD hh:mm:ss
	sprintf(pStr, "%d-%d-%d %d:%d:%d",
			local->tm_year+1900,
			local->tm_mon+1,
			local->tm_mday,
			local->tm_hour,
			local->tm_min,
			local->tm_sec);
			
	pStr[17] = '\0';
			
	return pStr;
}

char *GetShortTimeStr(char *pStr)
{
	if(!pStr)
		return NULL;
		
	time_t t = time(NULL);
	struct tm *local = localtime(&t);
	
	//hh:mm:ss
	sprintf(pStr, "%d:%d:%d",
			local->tm_hour,
			local->tm_min,
			local->tm_sec);
			
	pStr[8] = '\0';
			
	return pStr;
}

int GetDayofWeek()
{
	int nRt = -1;
	
	time_t t = time(NULL);
	struct tm *pTime = localtime(&t);
	
	char buf[4];
	strftime(buf, sizeof(buf), "%w", pTime);
	
	nRt = atoi(buf);
	
	return nRt;
}